package view;

import javafx.event.EventHandler;
import javafx.scene.Cursor;
import javafx.scene.Parent;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;

import java.io.IOException;


@SuppressWarnings({"ALL", "AlibabaAbstractClassShouldStartWithAbstractNaming"})
public abstract class AbstractWindow extends Stage {
    Parent root;
    private double xOffset;
    private double yOffset;


    public void setIcon(){

        getIcons().add(new Image("file:src/image/mainWindow/vx.png"));
    }
    public abstract void startWindow() throws IOException;

    /**
     * 窗口移动方法
     */
    public void move() {
        root.setOnMousePressed(event -> {
            xOffset = getX() - event.getScreenX();
            yOffset = getY() - event.getScreenY();
            getRoot().setCursor(Cursor.CLOSED_HAND);

        });
        root.setOnMouseDragged(event -> {
            setX(event.getScreenX() + xOffset);
            setY(event.getScreenY() + yOffset);
        });
        root.setOnMouseReleased(event -> {
            root.setCursor(Cursor.DEFAULT);
        });
    }

    /**
     * 获取root
     *
     * @return
     */
    public Parent getRoot() {
        return root;
    }

}